package  
{
  import flash.display.DisplayObjectContainer;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import flash.geom.Point;
	/**
   * ...
   * @author ivan
   */
  public class Scroller 
  {
    
    public function Scroller(parent:DisplayObjectContainer) 
    {
      this.parent = parent;
      
      parent.stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
	  parent.stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
	  parent.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    }
    
    private function onMouseDown(e:MouseEvent):void
    {
      downPoint = new Point(e.stageX, e.stageY);
	  parentDownPosition = new Point(parent.x, parent.y);
    }
	
	private function onMouseMove(e:MouseEvent):void
	{
		if (!downPoint) return;
		parent.x = parentDownPosition.x - (downPoint.x - e.stageX);
		parent.y = parentDownPosition.y - (downPoint.y - e.stageY);
	}
    
    private function onMouseUp(e:MouseEvent):void
    {
      downPoint = null;
    }
    
    private var parent:DisplayObjectContainer;
    private var downPoint:Point;
	private var parentDownPosition:Point;
  }

}